package zuo.algo.util;

import zuo.algo.data.LinkedNode;

public class LinkedUtils {

    public static void printLinked(LinkedNode node) {
        StringBuilder sb = new StringBuilder();
        while (node != null) {
            sb.append(node.val).append("->");
            node = node.next;
        }
        System.out.println(sb.substring(0, sb.length() - 2));
    }

    public static LinkedNode constructLinkedList(int[] arr) {
        if (arr == null || arr.length == 0) {
            return null;
        }
        LinkedNode root = new LinkedNode(arr[0]);
        LinkedNode node = root;
        for (int i = 1; i < arr.length; i++) {
            node.next = new LinkedNode(arr[i]);
            node = node.next;
        }
        return root;
    }
}
